package com.ysuedu.servlet;

import com.ysuedu.common.SetCode;
import com.ysuedu.dao.UserDao;
import com.ysuedu.entity.User;
import com.ysuedu.service.UserService;
import com.ysuedu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet(name = "UserRegistServlet")
public class UserRegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SetCode.setEncoding(request,response);
        String userAccount=request.getParameter("userAccount");
        String password=request.getParameter("userPassword");
        String userName = request.getParameter("userName");
        String identify = request.getParameter("identify");
        UserService userService=new UserServiceImpl();
        System.out.print(userAccount+":"+password);
        User user = new User();
        user.setUserAccount(userAccount);
        user.setUserPwd(password);
        user.setIdentity(Integer.valueOf(identify));
        user.setUserName(userName);
        user.setCreateDate(new Date());
        Boolean register = userService.register(user);
        PrintWriter writer=response.getWriter();
        if(register){
            writer.print("1");
        }else{
            writer.print("0");
        }
        writer.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
